package LeetCode.Simple;

/*
输入一个链表的头节点，从尾部到头反过来返回每一个节点的值(用数组返回)
输入:head = [1,3,2]
输出:[2,3,1]
 */

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;

class ListNode{
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Question003 {
    public int[] reversePrint(ListNode head){
        ListNode p = head;
        int[] out = new int[1024];
        int i = 0;
        Deque<Integer> de =  new ArrayDeque<>();
        while(p != null){
            i++;
            de.add(p.val);
            p = p.next;
        }
        for (int j = 0; j < i; j++) {
            out[j] = de.removeFirst();
        }
        return out;
    }

}
